<template>
  <div>
    <div class="min-container">
      <div class="con">
        <p class="title">我的消息</p>
        <div class="content">
          <div
            class="msg-item"
            v-for="(item, k) in dataList"
            :key="k"
            @click="handleView(item)"
          >
            <div>
              <i class="dot" :class="item.status == '0' ? 'error' : 'success'" />
              {{ item.noticeTitle || "无" }}
            </div>
            <div>{{ item.updateTime || "-" }}</div>
          </div>
        </div>
        <el-button
          type="primary"
          :disabled="dataList.length == 0"
          class="clear-btn"
          @click="cleanAll"
        >
          清除全部
        </el-button>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import { messageList, messageRead } from "@/api/control/order";
const router = useRouter();

const dataList = ref([]); // 数据列表
const queryParams = ref({
  status: 0,
  params: {
    pageNum: 1,
    pageSize: 10,
  },
});

onMounted(() => {
  getList();
});

// 获取消息列表
const getList = () => {
  messageList(queryParams.value).then((res) => {
    dataList.value = res.rows;
  });
};

// 查看消息详情
const handleView = (row) => {
  router.push({
    path: "/client/myMessage/messageDetails",
    query: {
      noticeId: row.noticeId,
    },
  });
};

// 一键已读
const cleanAll = () => {
  messageRead({ isAll: 2 }).then((res) => {
    ElMessage.success(res.msg);
    getList();
  });
};
</script>
<style lang="less" scoped>
.con {
  margin: 20px 0 300px;
  width: 100%;
  height: 626px;
  background: #ffffff;
  padding: 20px;
  position: relative;
  .title {
    font-size: 18px;
    margin-left: 30px;
    font-weight: 600;
  }
  .content {
    height: 434px;
    margin: 20px 30px;
    border: 1px solid #e3e8f0;
    overflow-y: auto;
    .msg-item {
      padding: 0 50px;
      width: 100%;
      height: 62px;
      display: flex;
      justify-content: space-between;
      border-bottom: 1px solid #e3e8f0;
      align-items: center;
      &:hover {
        cursor: pointer;
        background-color: rgb(247, 251, 255);
      }
      > div:first-child {
        font-weight: 600;
        font-size: 13px;
      }
      > div:last-child {
        color: #909090;
      }
      .dot {
        display: inline-block;
        width: 10px;
        height: 10px;
        border-radius: 50%;
        margin-right: 6px;
      }
      .success {
        background-color: #67c23a;
      }
      .error {
        background-color: #f56c6c;
      }
    }
  }
}
.clear-btn {
  width: 150px;
  height: 40px;
  position: absolute;
  right: 50px;
  bottom: 50px;
}
</style>
